<!DOCTYPE html>
<html>
<head>
    <title>攻略系列</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/plugins/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/plugins/jquery/jquery.min.js"></script>
    <script src="/js/plugins/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/strategyCatalogs.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.js"></script>
    <script src="/js/common.js"></script>
    <script>
        $(function () {
            var params = getParams();
            if (!params.strategyId) {
                return;
            }
            //获取攻略基本信息
            $.get('/strategies/' + params.strategyId, function (data) {
                $(".title").html(data.title);
            });
            //获取裸游标签的基本信息
            $.get('/strategies/tags', function (data) {
                    //渲染到页面的数据
                $(".tag").renderValues(data);
            });

            //大家堵在看
            $.get("/travels/commends" , function (data) {
                //渲染数据
                console.log(data);
                $(".hot").renderValues(data)
                //给a链接绑定事件
                $(".hot a[data-url]").click(function () {
                    var url = $(this).data('url');
                    var id = $(this).data('id');
                    window.location.href = url + id;
                });
            });


            var index = 1;
            //获取攻略分类数据
            $.get('/strategies/' + params.strategyId + "/catalogs", function (data) {
                $(".catalogs").renderValues({list: data}, {
                    getName: function (item, value) {
                        var temp = index;
                        if (index <= 9) {
                            temp = "0" + index;
                        }
                        $(item).html(temp + "/" + value);
                        index++;
                    }
                });
                //给a链接绑定事件
                $(".catalogs a[data-url]").click(function () {
                    var url = $(this).data('url');
                    var id = $(this).data('id');
                    window.location.href = url + id;
                });

            })


            //用于储存攻略评论的数组
            var commentData = [];
            //默认的储存
            //分页
            var currentPage = $("[name=currentPage]");
            var pageSize = $("[name=pageSize]");

            //默认加载游记(分页)
            query();

            //窗口滚动时事件
            $(window).scroll(function () {
                //网页卷上去的高度 + 网页中能看到高度 >= 网页全文高度
                if ($(document).scrollTop() + $(document).height() >= $(window).height()) {
                    //结果总数

                    var rows = $("[name=rows]").val();
                    //滚动到最页面底部，如果有数据就继续加载
                    if (commentData > rows) {
                        //设置currentPage+1
                        currentPage.val(parseInt(currentPage.val()) + 1);
                        query();
                    }

                }
            });

            function query() {
                //获取分页信息
                var pageValue = currentPage.val();
                var pageSizeValue = pageSize.val();
                $.get('strategies/comments', {currentPage: pageValue, pageSize: pageSizeValue}, function (data) {
                    $("#comment").renderValues(data, {
                        getImg: function (item, value) {
                            console.log(data);
                            //用分号切开 图片的平均
                            var str = value.split(';');
                            str.pop();
                            var img = "";
                            for (var i = 0; i < str.length; i++) {
                                img += '<li><img src="' + str[i] + '"></li>'
                            }

                            $(item).html(img);
                        },
                        //星星
                        getStar: function (item, value) {
                            var star = "";
                            var stars = "";
                            for (var i = 0; i < value; i++) {
                                star += '<i class="fa fa-star"></i>'
                            }
                            for (var i = 0; i<5 - value; i++) {
                                stars += '<i class="fa fa-star-o"></i>'
                            }
                            $(item).html(star + stars);

                        }
                    });

                    //给a链接绑定事件
                    $(".headImgUrlSkip a[data-url]").click(function () {
                        var url = $(this).data('url');
                        var id = $(this).data('uid');
                        window.location.href = url + id;
                    });
                    //给a链接绑定事件
                    $(".contentSkip a[data-url]").click(function () {

                        var url = $(this).data('url');
                        var id = $(this).data('did');
                        window.location.href = url + id;
                    });
                    //给a链接绑定事件
                    $(".icon a[data-url]").click(function () {
                        var url = $(this).data('url');
                        var id = $(this).data('cid');
                        window.location.href = url + id;
                    });
                    //图片点击
                    $(".comment-img img").click(function () {
                        $(document).dialog({
                            titleShow: false,
                            overlayClose: true,
                            content: '<div style="text-align: center;"><img width="100%" src="' + $(this).attr('src') + '"></div>'
                        });
                    });
                });

            }


            $("#commentBtn").click(function () {
                var id = $(this).val("id");
                window.location.href = "/strategyComment.html?strategyId=" + id;
            });


        })
    </script>

</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="javascript:history.go(-1);">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-10">
            <div class="input-group-sm search">
                <input class="form-control searchBtn" placeholder="搜索旅行攻略">
            </div>
        </div>
    </div>
</div>

<div class="container strategies">
    <h5 class="title">广州攻略</h5>
    <small><span>0</span>人阅读过此攻略</small>
    <div class="focus">
        <i class="fa fa-heart"><span> 0</span> 收藏</i>
        <i class="fa fa-thumbs-up"><span> 0</span> 点赞</i>
        <button class="btn">想去</button>
        <button class="btn">去过</button>
    </div>
</div>
<ul class="nav nav-pills nav-justified border border-left-0 border-top-0 border-right-0" id="pills-tab">
    <li class="nav-item ">
        <a class="nav-link active" id="pills-catalog-tab" data-toggle="pill" href="#pills-catalog">
            <span>攻略目录</span>
        </a>
    </li>
    <li class="nav-item">
        <a class="nav-link " id="pills-comment-tab" data-toggle="pill" href="#pills-comment">
            <span>骡友点评</span>
        </a>
    </li>
</ul>
<div class="tab-content " id="pills-tabContent">
    <div class="tab-pane fade show active" id="pills-catalog">
        <div class="container hot">
            <h6>大家都在看</h6>
            <div render-loop="list">
                    <a href="javascript:;" data-url="travelContent.html?id="
                       render-attr="data-id=list.id">
                    <button class="btn" render-html="list.title"></button>
                </a>

           </div>
        </div>
        <div class="catalogs">
            <div render-loop="list">
                <div class="container detail">
                    <h6 render-key="list.name" render-fun="getName"></h6>
                    <div render-loop="list.details">
                        <a href="javascript:;" data-url="strategyDetails.html?id="
                           render-attr="data-id=list.details.id">
                            <button class="btn" render-html="list.details.title"></button>
                        </a>
                    </div>
                </div>
            </div>
        </div>

    </div>
    <div class="tab-pane fade " id="pills-comment">

        <div class="container tag">
            <h6>骡友标签</h6>
            <div render-loop="self">
                <span render-html="self.name"></span>
            </div>
        </div>
        <hr>

        <input type="hidden" name="currentPage" value="1">
        <input type="hidden" name="pageSize" value="5">
        <input type="hidden" name="rows" render-value="rows">
        <div id="comment" name="skipHref">
            <div render-loop="list">
                <div class="container row comment">
                    <div class="col-2 comment-head headImgUrlSkip">
                        <a href="javascript:;" data-url="/mine/userProfiles.html?id="
                           render-attr="data-uid=list.user.id">

                            <img class="rounded-circle" render-src="list.user.headImgUrl">
                        </a>
                    </div>
                    <div class="col comment-right">
                        <p class="authorName"><span render-html="list.user.nickName"></span></p>
                        <!--星星-->
                        <span class="comment-star" render-key="list.starNum" render-fun="getStar">
                        </span>
                        <span class="comment-date" render-html="list.createTime"></span>
                        <div class="comment-content contentSkip">
                            <a href="javascript:;" data-url="strategyComment.html?id="
                               render-attr="data-did=list.user.id">
                                <p render-html="list.content"></p>
                            </a>
                        </div>

                        <ul class="comment-img" render-key="list.imgUrls" render-fun="getImg">

                        </ul>

                        <div class="d-flex icon">
                            <a href="javascript:;" data-url="strategyComment.html?id=" render-attr="data-cid=list.id">
                                <i class="fa  fa-commenting-o " style="margin-right: 10px"> 评论 </i>
                                <i class="fa fa-thumbs-o-up"> <span>0</span> </i>
                            </a>
                        </div>

                    </div>
                </div>

            </div>
        </div>
    </div>

</div>
</div>

<div class="operation">
    <button class="btn">加入旅行单</button>
    <button class="btn" id="commentBtn">点评</button>
</div>


</body>
</html>